const userModel = require('../models/users.model');

// 用户业务操作
const user = {
    /**
     * 验证用户注册信息
     */
    validatorRegister(ctx, formData) {
        let result = {
            "result": false,
            "message": ''
        };
        // 检验操作
        // if (!/^1\d{10}$/g.test(userInfo.phone)) {
        //     result.message = '手机号码为11位';
        //     return result;
        // }
        if (!/^\w+(@fudan.edu.cn)$/g.test(formData.email)) {
            result.message = '请使用复旦邮箱注册';
            return result;
        }
        if (!formData.passwordEncrypt) {
            result.message = '请输入密码';
            return result;
        }
        // 校验密码
        if (formData.passwordEncrypt.length < 6) {
            result.message = '密码长度大于6';
            return result;
        }
        result.result = true;
        return result;
    },
    /**
     * 验证邮箱唯一性
     */
    async isExist(formData) {
        let result = await userModel.isExist(formData);
        return result;
    },
    // 插入数据
    async insertInfo(formData) {
        let result = await userModel.insertInfo(formData);
        return result;
    },
    // 登录校验
    async signIn(formData) {
        let result = await userModel.signIn(formData);
        return result;
    },
    // 获取用户信誉积分 单一值
    async getCreditSingle(formData) {
        let result = await userModel.getCreditSingle(formData);
        return result;
    },
    // 获取用户信誉积分 平均值
    async getCreditAverage(formData) {
        let result = await userModel.getCreditAverage(formData);
        return result;
    },

    // 获取用户信息
    async getInfoById(formData) {
        let result = await userModel.getInfoById(formData);
        return result;
    },
    // 修改用户信息
    async modifyInfo(formData) {
        let result = await userModel.modifyInfo(formData);
        return result;
    },
    // 上传用户头像
    async upload_portrait(formData) {
        let result = await userModel.upload_portrait(formData);
        return result;
    },
    // 添加用户收藏
    async addCollect(formData) {
        let result = await userModel.addCollect(formData);
        return result;
    },
    // 查看用户收藏
    async collect(formData) {
        let result = await userModel.collect(formData);
        return result;
    },
    // 取消用户收藏
    async removeCollect(formData) {
        let result = await userModel.removeCollect(formData);
        return result;
    },

};
module.exports = user;